from typing import List

from app.models.posts import PostResponse
from pydantic import BaseModel, ConfigDict, validator


class UserCreate(BaseModel):
    username: str
    password: str

    @validator('password')
    def validate_password(cls, value):
        if not is_strong_password(value):
            raise ValueError("密码太弱。")
        return value
# 密码强度验证函数示例
def is_strong_password(password: str) -> bool:
    # 这里只是一个简单示例，实际应用中应根据需求调整密码强度规则
    if len(password) < 8:
        return False
    if not any(char.isdigit() for char in password):
        return False
    if not any(char.isupper() for char in password):
        return False
    if not any(char.islower() for char in password):
        return False
    return True


class UserResponse(UserCreate):

    posts: List[PostResponse]
    model_config = ConfigDict(from_attributes=True)
